package com.grts.mall.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.grts.mall.common.CommonResult;
import com.grts.mall.mapper.OrderItemMapper;
import com.grts.mall.mapper.ProductMapper;
import com.grts.mall.pojo.OrderItem;
import com.grts.mall.pojo.OrderItemExample;
import com.grts.mall.pojo.Product;
import com.grts.mall.pojo.vo.OrderItemVo;

@Service
public class OrderItemServiceImpl implements OrderItemService{
	
	@Autowired
	private OrderItemMapper orderItemMapper;
	
	@Autowired
	private ProductMapper productMapper;
	
	@Override
	public CommonResult find(Long oid) {
		List<OrderItemVo> vos = new ArrayList<OrderItemVo>();
		OrderItemExample example = new OrderItemExample();
		example.createCriteria().andOidEqualTo(oid);
		List<OrderItem> selectByExample = this.orderItemMapper.selectByExample(example);
		for (OrderItem orderItem : selectByExample) {
			Product pro = this.productMapper.selectByPrimaryKey(orderItem.getPid());
			OrderItemVo vo = new OrderItemVo(pro.getCover(), pro.getTitle(), pro.getPrice(),pro.getPid());
			vo.setQuantity(orderItem.getQuantity());
			vos.add(vo);
		}
		return CommonResult.success(vos);
	}

	
}
